////////////////////////////////////////////////////////////
//
// SFML GUI - Simple and Fast GUI Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) (for SFML)
// Copyright (C) 2010 Janniaux Alexandre (alexand69580@yahoo.fr) (for GUI)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
//    you must not claim that you wrote the original software.
//    If you use this software in a product, an acknowledgment
//    in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
//    and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////

#include "Widget.hpp"
#include "GuiListener.hpp"

namespace gui
{

Widget::Widget(Widget* parent) :
    sf::Drawable()
{
    SetParent(parent);
}

Widget* Widget::GetParent() const
{
    return myParent;
}

const sf::Rect<float>& Widget::GetRect() const
{
    return myRect;
}

const sf::Vector2f Widget::GetGlobalPosition() const
{
    if(myParent)
        return GetPosition() + myParent->GetGlobalPosition();
    else
        return GetPosition();
}

void Widget::SetParent(Widget* parent)
{
    myParent = parent;
    if(parent)
        parent->AddWidget(this);

}

void Widget::SetSize(float x, float y)
{
    myRect.Right = x;
    myRect.Bottom = y;
}

void Widget::SetSize(const sf::Vector2f& size)
{
    SetSize(size.x, size.y);
}

bool Widget::AcceptMouseEvent(int x, int y)
{
    if(!myParent)
    {
        if(myRect.Contains(x,y))
            return true;

    }
    return false;
}

void Widget::AddWidget(Widget* widget)
{
    if(widget)
        myChildren.push_back(widget);
}



void Widget::Render(sf::RenderTarget& target, sf::Renderer& renderer) const
{
    RenderWidget();
}

void RenderWidget(sf::RenderTarget& target, sf::Renderer& renderer) const
{

}

/*################*/
/* Mouse's events */
/*################*/

void Widget::OnMouseButtonPressed(sf::Event& mouseEvent)
{
}

void Widget::OnMouseButtonReleased(sf::Event& mouseEvent, bool onMe)
{
}

void Widget::OnMouseClicked(sf::Event& mouseEvent)
{
}

void Widget::OnMouseEntered(sf::Event& mouseEvent)
{
}

void Widget::OnMouseLeft(sf::Event& mouseEvent)
{
}

void Widget::OnMouseWheelMoved(sf::Event& mouseEvent)
{
}

/*################*/
/* Focus's events */
/*################*/

void Widget::OnFocusEntered(sf::Event& mouseEvent, int focusType)
{
}

void Widget::OnFocusLeft(sf::Event& mouseEvent)
{
}

/*###################*/
/* Keyboard's events */
/*###################*/

void Widget::OnKeyPressed(sf::Event& keyEvent)
{
}

void Widget::OnKeyReleased(sf::Event& keyEvent)
{
}

}; // namespace GUI

